//
//  MResumeGameLayer.m
//  Coffee
//
//  Created by sabhanayagam b on 5/1/11.
//  Copyright 2011 Cognizant. All rights reserved.
//

#import "MResumeGameLayer.h"
#import "GameManager.h"

@implementation MResumeGameLayer
// on "init" you need to initialize your instance
-(id) init
{
	// always call "super" init
	// Apple recommends to re-assign "self" with the "super" return value
	if( (self=[super init] )) {
		self.isTouchEnabled = YES; 

		//Play
		CCLabelTTF *playLabel = [CCLabelTTF labelWithString:@"Resume" fontName:@"Marker Felt" fontSize:24];
		CCMenuItemLabel *play = [CCMenuItemLabel itemWithLabel:playLabel target:self selector:@selector(resumeHandler:)];
		
		//Levels
		CCLabelTTF *levelLabel = [CCLabelTTF labelWithString:@"Restart" fontName:@"Marker Felt" fontSize:24];
		CCMenuItemLabel *level = [CCMenuItemLabel itemWithLabel:levelLabel target:self selector:@selector(restartHandler:)];
		
		//Settings
		CCLabelTTF *settingsLabel = [CCLabelTTF labelWithString:@"Main Menu" fontName:@"Marker Felt" fontSize:24];
		CCMenuItemLabel *settings = [CCMenuItemLabel itemWithLabel:settingsLabel target:self selector:@selector(backToMainHandler:)];
		
		
		//Main Container
		CCMenu *menu = [CCMenu menuWithItems: play, level,settings, nil];
		[menu alignItemsVertically];
		[menu setColor:ccBLACK];
		[self addChild: menu z:0 tag:STATUS_BAR];
		
	}
	return self;
}
//Button Click handlers
-(void) resumeHandler: (id) sender
{
	[[GameManager sharedGameInfo] resumeGame];
	[(CCMultiplexLayer*)parent_ switchTo:0];

}
-(void) restartHandler: (id) sender
{
	[[GameManager sharedGameInfo] restartLevel];
}
-(void) backToMainHandler: (id) sender
{
	[[GameManager sharedGameInfo]restartGame];
}
-(void) registerWithTouchDispatcher
{
	[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:-2 swallowsTouches:YES];
}

// Implements logic to check if the touch location was in an area that this layer wants to handle as input.
-(bool) isTouchForMe:(CGPoint)touchLocation
{
	CCNode* node = [self getChildByTag:PAUSE_GAME];
	return CGRectContainsPoint([node boundingBox], touchLocation);
}

-(BOOL) ccTouchBegan:(UITouch*)touch withEvent:(UIEvent *)event
{
	CGPoint location = [GameManager locationFromTouch:touch];
	bool isTouchHandled = [self isTouchForMe:location];
	// Always swallow touches, GameLayer is the last layer to receive touches.
	return isTouchHandled;
}

// on "dealloc" you need to release all your retained objects
- (void) dealloc
{
	// in case you have something to dealloc, do it in this method
	// in this particular example nothing needs to be released.
	// cocos2d will automatically release all the children (Label)
	
	// don't forget to call "super dealloc"
	[super dealloc];
}
@end
